package com.campus.counseling.util;

import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.stereotype.Component;

@Component
public class UserAgentAnalyzer {
    
    /**
     * 解析User-Agent字符串
     */
    public UserAgent parseUserAgent(String userAgentString) {
        return UserAgent.parseUserAgentString(userAgentString);
    }
    
    /**
     * 获取浏览器名称和版本
     */
    public String getBrowserInfo(UserAgent userAgent) {
        return userAgent.getBrowser().getName() + " " + userAgent.getBrowserVersion();
    }
    
    /**
     * 获取操作系统名称
     */
    public String getOperatingSystem(UserAgent userAgent) {
        return userAgent.getOperatingSystem().getName();
    }
    
    /**
     * 获取设备类型
     */
    public String getDeviceType(UserAgent userAgent) {
        switch (userAgent.getOperatingSystem().getDeviceType()) {
            case MOBILE:
                return "Mobile";
            case TABLET:
                return "Tablet";
            case COMPUTER:
                return "Desktop";
            default:
                return "Unknown";
        }
    }
} 